package com.yty.demo._4_oop.innerclass;

/**
 * @author: yangtaoyao
 * @time: 2020/1/10 11:40
 * @description: 内部类
 */
public class ClassWithInnerClass {
    public static int aStaticInt;
    public int anInt=0;

    //普通内部类对象依赖外部类对象而存在,像外部类声明的一个属性字段一样
    public class InnerClass1{
        //非static内部类不可有static成员
        //public static int anInt=0;
        public int anInt=0;
        public String name;
        public void mb(){
            anInt=100;
            System.out.println("在内部类中 anInt="+anInt);
        }

        public InnerClass1(){
            System.out.println("InnerClass1 构造函数");
            anInt=InnerClass2.anInt;
        }
    }

    public static class InnerClass2{
        private static int anInt=2;
        private  String name;
        public InnerClass2(){
            System.out.println("InnerClass2 构造函数");
        }
    }

    public static void main(String[] args) {
        ClassWithInnerClass c1=new ClassWithInnerClass();
        InnerClass1 innerClass1=c1.new InnerClass1();
    }
}
class Test{
    public static void main(String[] args) {
        ClassWithInnerClass c1=new ClassWithInnerClass();
        ClassWithInnerClass.InnerClass1 innerClass1 =c1.new InnerClass1();
//        c1.ma();
        innerClass1.mb();

        ClassWithInnerClass.InnerClass2 innerClass2=new ClassWithInnerClass.InnerClass2();


    }
}